#import "PhotographWatermarkPlugin.h"

#import "CCScanQRcodeVC.h"


@interface PhotographWatermarkPlugin()


@property(nonatomic,strong) UIViewController *hostVC;


@end


@implementation PhotographWatermarkPlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
  FlutterMethodChannel* channel = [FlutterMethodChannel
      methodChannelWithName:@"ktx.com.photographWatermark"
            binaryMessenger:[registrar messenger]];
  PhotographWatermarkPlugin* instance = [[PhotographWatermarkPlugin alloc] init];
    
//       instance.hostViewController = UIApplication.shared.delegate?.window??.rootViewController
    
  instance.hostVC   =  [UIApplication sharedApplication].delegate.window.rootViewController;
    
   
    
    
  [registrar addMethodCallDelegate:instance channel:channel];
}

- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
  if ([@"getPlatformVersion" isEqualToString:call.method]) {
    result([@"iOS " stringByAppendingString:[[UIDevice currentDevice] systemVersion]]);
  }else if([@"takePhoto" isEqualToString:call.method]) {
      
      if(call.arguments != nil){
          NSLog(@"%@",call.arguments);
//         NSString *paramas   = call.arguments;
//          NSData * getJsonData = [paramas dataUsingEncoding:NSUTF8StringEncoding];
//          NSDictionary * dict = [NSJSONSerialization JSONObjectWithData:getJsonData options:NSJSONReadingMutableContainers error:nil];
          NSDictionary * dict = call.arguments;
          CCScanQRcodeVC   *vc  = [CCScanQRcodeVC new];
          vc.name  = dict[@"name"];
          vc.time   = dict [@"time"];
          vc.address   = dict [@"address"];
              vc.result = ^(NSString * path) {
                result(path);
              };
              
              UINavigationController  *nav  = [[UINavigationController alloc] initWithRootViewController:vc];
              if (@available(iOS 13.0, *)) {

                    nav.modalPresentationStyle = UIModalPresentationFullScreen;
              }

            [self.hostVC  presentViewController:nav animated:NO completion:nil];
          
      }

      

//UIImage   *image1  =   [UIImage imageNamed:@"icon_return" inBundle:[[NSBundle bundleForClass:[PhotographWatermarkPlugin class]] pathForResource:@"MainLibrary" ofType:@"bundle"] withConfiguration:nil];

      
    
//
      
    
//      let scannerViewController = BarcodeScannerViewController()
//
//            let navigationController = UINavigationController(rootViewController: scannerViewController)
//
//            if #available(iOS 13.0, *) {
//                navigationController.modalPresentationStyle = .fullScreen
//            }
//
//            if let config = config {
//                scannerViewController.config = config
//            }
//            scannerViewController.delegate = self
//            hostViewController?.present(navigationController, animated: false)
      
      

  } else {
    result(FlutterMethodNotImplemented);
  }
}

@end
